#include "newton.h"
#include <iostream>
#include <vector>

// 样本数据
double days[] = {0, 6, 10, 13, 17, 20, 28};
double sp1Weights[] = {6.67, 17.3, 42.7, 37.3, 30.1, 29.3, 28.7};
double sp2Weights[] = {6.67, 16.1, 18.9, 15.0, 10.6, 9.44, 8.89};
const int dataSize = sizeof(days) / sizeof(double);

int main() {
    // 使用给定数据进行牛顿插值
    Newton_1 interpolatorSp1(days, dataSize, sp1Weights);
    Newton_1 interpolatorSp2(days, dataSize, sp2Weights);

    // 打印近似的重量曲线
    std::cout << "Approximated weight curve for Sp1:" << std::endl;
   for (int i = 0; i < dataSize; i++) {
    double day = days[i];
        std::cout << "Day " << day << ": " << interpolatorSp1.interpolate(day) << "g" << std::endl;
    }

    std::cout << "\nApproximated weight curve for Sp2:" << std::endl;
    for (int i = 0; i < dataSize; i++) {
    double day = days[i];
        std::cout << "Day " << day << ": " << interpolatorSp2.interpolate(day) << "g" << std::endl;
    }

    // 对15天后的重量进行预测
    double predictedSp1Weight = interpolatorSp1.interpolate(28 + 15);
    double predictedSp2Weight = interpolatorSp2.interpolate(28 + 15);

    std::cout << "\nPredicted weight for Sp1 after 15 days: " << predictedSp1Weight << "g" << std::endl;
    std::cout << "Predicted weight for Sp2 after 15 days: " << predictedSp2Weight << "g" << std::endl;

    // 基于预测的重量判断是否会死亡
    if (predictedSp1Weight <= 0) {
        std::cout << "\nSp1 is predicted to die after 15 days." << std::endl;
    } else {
        std::cout << "\nSp1 is predicted to survive after 15 days." << std::endl;
    }

    if (predictedSp2Weight <= 0) {
        std::cout << "Sp2 is predicted to die after 15 days." << std::endl;
    } else {
        std::cout << "Sp2 is predicted to survive after 15 days." << std::endl;
    }

    return 0;
}
